﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using System.Data.Common;
using Mocola.BLL;
using Mocola.Model;

namespace Mocola.Net.Web.ajax
{
    public partial class UpdateMMap : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(Request.QueryString["id"]))
            {
                MembershipCreateStatus status = new MembershipCreateStatus();
                DbTransaction transaction = Databases.MocolaNet.BeginTransaction(IsolationLevel.ReadCommitted);

                try
                {
                    int ID = Convert.ToInt32(Request.QueryString["id"]);
                    string pTid = getRequest("Tid");
                    string pEid = getRequest("Eid");
                    string pMingCheng = getRequest("MingCheng");        // 名称
                    string pJueDingHao = getRequest("JueDingHao");      // 决定号
                    string pTuZhiBianHao = getRequest("TuZhiBianHao");  // 图纸编号
                    string pZhuanYeLeiBie = getRequest("ZhuanYeLeiBie");  // 专业类别

                    string pJiShouRiQi = getRequest("JieShouRiQi_Nian") + "-" + getRequest("JieShouRiQi_Yue") + "-" + getRequest("JieShouRiQi_Ri");      // 接收时间
                    string pChuTuRiQi = getRequest("ChuTuRiQi_Nian") + "-" + getRequest("ChuTuRiQi_Yue") + "-" + getRequest("ChuTuRiQi_Ri");      // 竣工时间

                    string pSheJiDanWei = getRequest("SheJiDanWei");    // 设计单位

                    string pBanBen = getRequest("BanBen");          // 版本
                    string pTuFu = getRequest("TuFu");              // 图幅
                    string pZhang = getRequest("Zhang");            // 张
                    string pTao = getRequest("Tao");                // 套
                    string pShuLiang = getRequest("ShuLiang");      // 数量

                    string pZaiTi = getRequest("ZaiTi");      // 载体

                    string pCaiZhi = getRequest("CaiZhi");      // 材质
                    string pMiJi = getRequest("MiJi");          // 密级
                    string pBaoGuanQiXian = getRequest("BaoGuanQiXian");          // 保管期限

                    string pZhuangTai = getRequest("ZhuangTai");          // 状态
                    string pBeiZhu = getRequest("BeiZhu");      // 备注

                    bool bUpdated = Databases.MocolaNet.Update(Moc_MMapsInfo.Moc_MMaps)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.Name, pMingCheng)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.JueDingHao, pJueDingHao)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.TuZhiBianHao, pTuZhiBianHao)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.ZhuanYeLeiBie, pZhuanYeLeiBie)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.ChuTuRiQi, pChuTuRiQi)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.SheJiDanWei, pSheJiDanWei)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.BanBen, pBanBen)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.TuFu, pTuFu)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.Zhang, pZhang)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.Tao, pTao)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.ShuLiang, pShuLiang)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.ZaiTi, pZaiTi)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.CaiZhi, pCaiZhi)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.MiJi, pMiJi)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.BaoGuanQiXian, pBaoGuanQiXian)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.ZhuangTai, pZhuangTai)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.JiShouRiQi, pJiShouRiQi)
                                 .AddColumn(Moc_MMapsInfo.Moc_MMaps.BeiZhu, pBeiZhu)
                                 .Where(Moc_MMapsInfo.Moc_MMaps.ID == ID)
                                 .SetTransaction(transaction)
                                 .Execute() == 1;
                    if (bUpdated)
                    {
                        Response.Write("图纸更新成功！");
                        status = MembershipCreateStatus.Success;
                    }
                    else
                    {
                        Response.Write("图纸更新失败！");
                        status = MembershipCreateStatus.ProviderError;
                    }
                }
                catch (Exception ex)
                {
                    Response.Write(ex.Message);
                    status = MembershipCreateStatus.ProviderError;
                }
                finally
                {
                    if (status == MembershipCreateStatus.Success)
                        transaction.Commit();
                    else
                        transaction.Rollback();
                    Databases.MocolaNet.CloseConnection(transaction);
                }
            }
        }

        private string getRequest(string pReqID)
        {
            return string.IsNullOrEmpty(Request.Form[pReqID]) ? string.Empty : Request.Form[pReqID].ToString();
        }
    }
}
